{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d3fbb320",
   "metadata": {},
   "source": [
    "## Numpy.array的基本操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "b73eba9c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "e62574af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.arange(10)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "f0985dc2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.arange(15).reshape(3, 5)\n",
    "X"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "074f4040",
   "metadata": {},
   "source": [
    "### 基本属性"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d28c935",
   "metadata": {},
   "source": [
    "查看数组是几维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "eb0ad8b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "5557b52c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10,)"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "f6e18d0a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 5)"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a23d912",
   "metadata": {},
   "source": [
    "shape返回数组维度信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c90a78ac",
   "metadata": {},
   "source": [
    "### numpy.array的数组访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "8886d2c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "008524c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "6d6ad3fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "7f596607",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[0][0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19f0001f",
   "metadata": {},
   "source": [
    "X[0][0]这种访问形式不推荐使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "4b365b9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[2, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "03ea459e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 2, 4, 6, 8])"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "424300ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "020f0901",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2a4f001",
   "metadata": {},
   "source": [
    "访问二维数组的前2行前3列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "568373e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [5, 6, 7]])"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:2, :3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "0b2648d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4],\n",
       "       [5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:2][:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6034da3",
   "metadata": {},
   "source": [
    "X[:2][:3] 表示先截取二维数组的前2行，截取完之后就是一个2行的二维数组，再截取前3行结果还是一样的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "8284affa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 2, 4],\n",
       "       [5, 7, 9]])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:2, ::2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7da31e90",
   "metadata": {},
   "source": [
    "X[:2, ::2]访问前2行，每一行间隔为2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "396b78c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[14, 13, 12, 11, 10],\n",
       "       [ 9,  8,  7,  6,  5],\n",
       "       [ 4,  3,  2,  1,  0]])"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[::-1, ::-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0f58af0",
   "metadata": {},
   "source": [
    "X[::-1, ::-1] 行和列全部倒序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "e4bc4238",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4])"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "8dda015b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4])"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[0, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d39cdf9",
   "metadata": {},
   "source": [
    "上面两种都表示取第一行的数据，最终是一个一维的向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "28bcb2d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  5, 10])"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:, 0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f7367a5",
   "metadata": {},
   "source": [
    "X[:, 0] 表示取第一列的数据，最终也是一个一维的向量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8544faa",
   "metadata": {},
   "source": [
    "numpy进行切片，产生的新的数组跟原始对象是有引用关系的，如果新数组或者原始数组修改了，都会同步修改，这个跟python里面不一样，这样做的目的是提升效率，如果要产生一个新的，可以用copy()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "1e1a2120",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [5, 6, 7]])"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "subX = X[:2, :3].copy()\n",
    "subX"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de7c91f2",
   "metadata": {},
   "source": [
    "### reshape 转多维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "990702d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.reshape(1, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "5f54abbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.reshape(-1, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "8ed9d895",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3, 4],\n",
       "       [5, 6, 7, 8, 9]])"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.reshape(2, -1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f09a770b",
   "metadata": {},
   "source": [
    "参数里面的-1表示的是，按元素自动生成，比如(2, -1)表示生成一个2行，至于列根据元素自动计算"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3a3ed8a",
   "metadata": {},
   "source": [
    "### 合并操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "8e2a8c0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.array([1, 2, 3])\n",
    "y = np.array([3, 2, 1 ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "6f8d5722",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "b6f6f728",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 2, 1])"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "10519831",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 3, 2, 1])"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.concatenate([x, y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "852e90eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([[1, 2, 3], \n",
    "             [4, 5, 6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "91c801a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.concatenate([A, A])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "9f567a1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7,  4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11,  8,  9, 10, 11],\n",
       "       [12, 13, 14, 15, 12, 13, 14, 15]])"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.concatenate([A, A], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "ae9adf11",
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([[1, 2, 3], \n",
    "             [4, 5, 6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "e531d7d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([666, 666, 666])"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z = np.array([666, 666, 666])\n",
    "z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "73af1ca9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[666, 666, 666]])"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z1 = z.reshape(1, -1)\n",
    "z1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "030a01e4",
   "metadata": {},
   "source": [
    "默认是按行进行拼接的，axis指定1就按列进行拼接"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b7bc86b",
   "metadata": {},
   "source": [
    "二维和一维是不能直接拼接的，需要将一维转成二维之后再进行拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "60617990",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1,   2,   3],\n",
       "       [  4,   5,   6],\n",
       "       [666, 666, 666]])"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.concatenate([A, z1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09f52531",
   "metadata": {},
   "source": [
    "vstack是np提供的在垂直方向将数据叠加到一起，内部自动转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "95ffac4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1,   2,   3],\n",
       "       [  4,   5,   6],\n",
       "       [666, 666, 666]])"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack([A, z])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22d80230",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "7922c4c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[100, 100],\n",
       "       [100, 100]])"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B = np.full((2, 2), 100)\n",
    "B"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "003a6e63",
   "metadata": {},
   "source": [
    "hstack在水平方向将数据叠加到一起"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "dabb0204",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1,   2,   3, 100, 100],\n",
       "       [  4,   5,   6, 100, 100]])"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack([A, B])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9f6845f",
   "metadata": {},
   "source": [
    "### 分割操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "c79d69bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.arange(10)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "b9320f43",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1, x2, x3 = np.split(x, [3, 7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "bd3d93cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2])"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "0c2e09e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 4, 5, 6])"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "64b66a20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([7, 8, 9])"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "198e67e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1, x2 = np.split(x, [5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "66f5fee6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.arange(16).reshape(4, 4)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "1c4c1af9",
   "metadata": {},
   "outputs": [],
   "source": [
    "A1, A2 = np.split(A, [2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "29f65e2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3],\n",
       "       [4, 5, 6, 7]])"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "e2033dfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "55c1ecd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "A1, A2 = np.split(A, [2], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "ea08c7a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 4,  5],\n",
       "       [ 8,  9],\n",
       "       [12, 13]])"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "a5538664",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  3],\n",
       "       [ 6,  7],\n",
       "       [10, 11],\n",
       "       [14, 15]])"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "8312c2bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "upper, lower = np.vsplit(A, [2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "d4f5db57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2, 3],\n",
       "       [4, 5, 6, 7]])"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "upper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "853c8a56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lower"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "2d00b2c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "left, right = np.hsplit(A, [2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "cf0dbb6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 4,  5],\n",
       "       [ 8,  9],\n",
       "       [12, 13]])"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "left"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "0e90feff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  3],\n",
       "       [ 6,  7],\n",
       "       [10, 11],\n",
       "       [14, 15]])"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "right"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11e823b6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
